package com.blrs.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.blrs.VO.ClassVO;
import com.blrs.common.annotation.Anonymous;
import com.blrs.common.core.page.PageDomain;
import com.blrs.common.core.page.TableSupport;
import com.blrs.common.utils.SecurityUtils;
import com.blrs.common.utils.page.PaginationUtil;
import com.blrs.service.project.afterSales.IProjectSalesService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.blrs.common.annotation.Log;
import com.blrs.common.core.controller.BaseController;
import com.blrs.common.core.domain.AjaxResult;
import com.blrs.common.enums.BusinessType;
import com.blrs.domain.ProjectSales;
import com.blrs.common.utils.poi.ExcelUtil;
import com.blrs.common.core.page.TableDataInfo;

/**
 * 项目售后Controller
 * 
 * @author yang
 * @date 2023-12-07
 */
@RestController
@RequestMapping("/project/sales")
public class ProjectSalesController extends BaseController
{
    @Autowired
    private IProjectSalesService projectSalesService;

    /**
     * 查询项目售后列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ProjectSales projectSales)
    {
        startPage();
        List<ProjectSales> list = projectSalesService.selectProjectSalesList(projectSales);
        return getDataTable(list);
    }

    /**
     * 导出项目售后列表
     */
    @Log(title = "项目售后", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProjectSales projectSales)
    {
        List<ProjectSales> list = projectSalesService.selectProjectSalesList(projectSales);
        ExcelUtil<ProjectSales> util = new ExcelUtil<ProjectSales>(ProjectSales.class);
        util.exportExcel(response, list, "项目售后数据");
    }

    /**
     * 获取项目售后详细信息
     */
    @GetMapping(value = "/{afterSalesId}")
    public AjaxResult getInfo(@PathVariable("afterSalesId") String afterSalesId)
    {
        return success(projectSalesService.selectProjectSalesByAfterSalesId(afterSalesId));
    }

    /**
     * 新增项目售后
     */
    @Log(title = "项目售后", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProjectSales projectSales) throws NoSuchFieldException, IllegalAccessException {
        return toAjax(projectSalesService.insertProjectSales(projectSales));
    }

    /**
     * 修改项目售后
     */
    //@PreAuthorize("@ss.hasPermi('project:sales:edit')")
    @Log(title = "项目售后", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProjectSales projectSales)
    {
        return toAjax(projectSalesService.updateProjectSales(projectSales));
    }

    /**
     * 删除项目售后
     */
    @Log(title = "项目售后", businessType = BusinessType.DELETE)
	@DeleteMapping("/{afterSalesIds}")
    public AjaxResult remove(@PathVariable String[] afterSalesIds)
    {
        return toAjax(projectSalesService.deleteProjectSalesByAfterSalesIds(afterSalesIds));
    }

    /**
     * 批量修改主分类
     */
    @PutMapping("/updateClass")
    public AjaxResult updateClass(@RequestBody ClassVO classVO) throws Exception
    {
        projectSalesService.updateClassIds(classVO.getEnterIds(),classVO.getClassId());
        return success("修改成功");
    }

    /**
     * 获取当前用户的服务机构名称
     */
    @GetMapping("/getOrgUserName")
    @Anonymous
    public AjaxResult getOrgUserName(){
        return success(SecurityUtils.getOrgName());
    }
}
